const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
    return sequelize.define(
        'sys_user',
        {
            id: {
                autoIncrement: true,
                type: DataTypes.BIGINT,
                allowNull: false,
                primaryKey: true,
                comment: '用户ID',
            },
            mobile: {
                type: DataTypes.STRING(20),
                allowNull: false,
                comment: '手机号（登录账号，与员工表mobile关联）',
                unique: 'mobile',
            },
            password: {
                type: DataTypes.STRING(100),
                allowNull: false,
                defaultValue: '000000',
                comment: '密码（建议BCrypt加密）',
            },
            status: {
                type: DataTypes.TINYINT,
                allowNull: false,
                defaultValue: 1,
                comment: '状态：1-启用，0-禁用',
            },
            last_login_time: {
                type: DataTypes.DATE,
                allowNull: true,
                comment: '最后登录时间',
            },
            create_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
            update_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
        },
        {
            sequelize,
            tableName: 'sys_user',
            timestamps: false,
            indexes: [
                {
                    name: 'PRIMARY',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'id' }],
                },
                {
                    name: 'mobile',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'mobile' }],
                },
                {
                    name: 'idx_mobile',
                    using: 'BTREE',
                    fields: [{ name: 'mobile' }],
                },
            ],
        },
    );
};
